<?php
/**
 * @产业报告类
 * 1、产业报告列表
 * 2、产业报告详情
 * 3、产业报告编辑/添加
 * 4、产业报告删除
 * 5、产业报告开启禁用
 *
 * @作者
 * 万全强（php）
 */
namespace app\controller;

use app\controller\HomeBase;
use think\facade\Db;


use app\model\ReportModel;


class Report extends HomeBase
{
	
	private $ReportModel;
	private $RoleId=0;
	
	public function __construct(){
		
		parent::__construct();
		
		$this->ReportModel=new ReportModel();
		
	}
	/**
	 * 产业报告列表
	 *
	 * @return void
	 */
	public function GetReportList()
	{
		$param=request()->param();
		$where="1=1 and status =1 ";
		if(isset($param['keywords'])&&!empty($param['keywords'])){
			$where.=" and name like '%".trim($param['keywords'])."%'";
		}
		if(isset($param['status'])&&strlen($param['status'])>0){
			$where.=" and status = '{$param['status']}'";
		}
		
		if(isset($param['chain_id'])&&!empty($param['chain_id'])){
			$where.=" and FIND_IN_SET('{$param['chain_id']}',chain_id) ";
		}
		if(isset($param['yun_chain_id'])&&!empty($param['yun_chain_id'])){
			$where.=" and FIND_IN_SET('{$param['yun_chain_id']}',chain_id) ";
		}
		
		if(isset($param['id'])&&!empty($param['id'])){
			$where.=" and role_id=".$param['id'];
		}else{
			if($this->user_id!=1&&!empty($this->role_id)){
				$where.=" and role_id=".$this->role_id;
			}
		}
		
		$res=$this->ReportModel->GetList($where);
		return json(['status'=>1,'msg'=>'获取成功','data'=>$res]);
	}
	/**
	 * 产业报告详情
	 *
	 * @return void
	 */
	public function GetReportDetail()
	{
		$param=request()->param();
		$id=isset($param['id'])?intval($param['id']):0;
		$result=$this->ReportModel->detail($id);
		
		return json(['status'=>1,'msg'=>'获取成功','data'=>$result]);
		
	}
	/**
	 * 产业报告添加/编辑
	 *
	 * @return void
	 */
	public function ReportEdit()
	{
		$param=request()->param();
		$id=isset($param['id'])?intval($param['id']):0;
		
		//表单验证
		try {
			$re=$this->validate($param,'app\validate\ReportValidate');
		} catch (\Exception $e) {
			return json(['status'=>0,'msg'=>$e->error,'data'=>[]]);
		}
		
		//管理表
		if($id){
			$id= $this->ReportModel->EditData($param,$id);
		}else{
			$param['role_id']=$this->role_id;
			$id= $this->ReportModel->AddData($param);
		}
		
		return json(['status'=>1,'msg'=>'操作成功','data'=>['id'=>$id]]);
	}
	/**
	 * 产业报告删除
	 *
	 * @return void
	 */
	public function ReportDel()
	{
		$param=request()->param();
		$id=isset($param['id'])?trim($param['id']):'';
		
		$result=$this->ReportModel->Del(explode(',',$id));
		if($result){
			return json(['status'=>1,'msg'=>'删除成功','data'=>[]]);
		}else{
			return json(['status'=>0,'msg'=>'删除失败','data'=>[]]);
		}
	}
	/**
	 * 产业报告是否开启禁用
	 *
	 * @return void
	 */
	public function UpdateReportStatus()
	{
		$param=request()->param();
		$id=isset($param['id'])?intval($param['id']):0;
		
		$result=$this->ReportModel->UpdateStatus($id);
		if($result){
			return json(['status'=>1,'msg'=>'操作成功','data'=>[]]);
		}else{
			return json(['status'=>0,'msg'=>'操作失败','data'=>[]]);
		}
	}
	
}
